package cn.enilu.flash.mobile.controller;

import cn.enilu.flash.bean.entity.bus.Collection;
import cn.enilu.flash.bean.entity.bus.Menu;
import cn.enilu.flash.bean.entity.bus.MenuFoods;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.bus.*;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.Lists;
import cn.enilu.flash.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/menu/foods")
public class MenuFoodsController extends BaseController {

    @Autowired
    private BusMenuService busMenuService;

    @Autowired
    private MenuFoodsService menuFoodsService;

    @Autowired
    private FoodsService foodsService;

    @GetMapping(value = "/list")
    public Object list(@RequestParam String menuDate) {
        List<SearchFilter> filters = Lists.newArrayList(
                SearchFilter.build("state", SearchFilter.Operator.EQ, "1"),
                SearchFilter.build("menuDate", SearchFilter.Operator.EQ, DateUtil.parseDate(menuDate))
        );
        List<Menu> menus = busMenuService.queryAll(filters);
        if (!CollectionUtils.isEmpty(menus)) {
            List<Long> ids = Lists.newArrayList();
            menus.forEach(item -> {
                ids.add(item.getId());
            });
            List<MenuFoods> menuFoods = menuFoodsService.queryAll(SearchFilter.build("menuId", SearchFilter.Operator.IN, ids));
            return Rets.success(menuFoods);
        } else {
            return Rets.success(Lists.newArrayList());
        }
    }

}
